#******************************************************************
#
# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Import('stacksamples_env')

samples_env = stacksamples_env.Clone()
######################################################################
# Build flags
######################################################################
samples_env.PrependUnique(CPPPATH=[
    '../../../../logger/include',
    '../../../../include',
    '../../../../stack/include',
    '../../../../security/include',
    '../../../../../oc_logger/include'
])

target_os = samples_env.get('TARGET_OS')
if target_os not in ['windows']:
    samples_env.AppendUnique(CXXFLAGS=['-std=c++0x', '-Wall', '-pthread'])

    # Note: 'pthread' is in libc for android.
    if target_os != 'android':
        samples_env.AppendUnique(LIBS=['pthread'])
    samples_env.Append(LINKFLAGS=['-Wl,--no-as-needed'])

if target_os in ['windows', 'msys_nt']:
    samples_env.PrependUnique(LIBS=['coap', 'ocsrm'])
else:
    samples_env.PrependUnique(LIBS=['connectivity_abstraction', 'coap', 'm'])

samples_env.PrependUnique(LIBS=['octbstack'])

if samples_env.get('SECURED') == '1':
    samples_env.AppendUnique(LIBS=['mbedtls', 'mbedx509', 'mbedcrypto'])

if target_os == 'android':
    samples_env.AppendUnique(CXXFLAGS=['-frtti', '-fexceptions'])
    samples_env.AppendUnique(LIBS=['gnustl_shared'])
    samples_env.AppendUnique(
        CPPDEFINES=['_GLIBCXX_USE_C99=1', '_GLIBCXX_HAVE_WCSTOF=1'])

    if not samples_env.get('RELEASE'):
        samples_env.AppendUnique(LIBS=['log'])

if target_os in ['darwin', 'ios']:
    samples_env.AppendUnique(CPPDEFINES=['_DARWIN_C_SOURCE'])

samples_env.AppendUnique(CPPDEFINES=['TB_LOG'])

######################################################################
# Source files and Targets
######################################################################

ocserverbasicops = samples_env.Program(
    'ocserverbasicops', ['common.cpp', 'ocserverbasicops.cpp'])
occlientbasicops = samples_env.Program(
    'occlientbasicops', ['common.cpp', 'occlientbasicops.cpp'])
ocamsservice = samples_env.Program(
    'ocamsservice', ['common.cpp', 'ocamsservice.cpp'])
ocsamples = [ocserverbasicops, occlientbasicops, ocamsservice]

ocsamples += samples_env.ScanJSON('resource/csdk/stack/samples/linux/secure')

Alias("samples", ocsamples)
samples_env.AppendTarget('samples')
samples_env.UserInstallTargetExtra(ocsamples)
